(* Tom Taylor
   3707 Poinciana Dr. #137
   Santa Clara, CA 95051 *)

DEFINITION MODULE PBFileManager;

(* This module defines the low level
   file system described in the latest
   File Manager documentation.  The
   types and procedures defined in
   this module support both MFS and
   HFS calls. *)
 
  FROM OSQueues IMPORT
    QElemPtr;
  FROM MacSystemTypes IMPORT
    LongCard, Ptr, OsErr,
    StringPtr;
  FROM FileManager IMPORT
    FInfo;
  FROM SYSTEM IMPORT
    ADDRESS;

  EXPORT QUALIFIED
  
  (* Types *)
    ParamBlkType, ParmBlkPtr, ParamBlockRec,
    CMovePBPtr, CMovePBRec, HParmBlkPtr,
    HParamBlockRec, WDPBPtr, WDPBRec,
    CInfoType, CInfoPBPtr, CInfoPBRec,
    FCBPBPtr, FCBPBRec,
    
  (* Procedures *)
    PBMountVol, PBGetVInfo, PBHGetVInfo,
    PBHSetVInfo, PBGetVol, PBHGetVol,
    PBSetVol, PBHSetVol, PBFlushVol,
    PBUnmountVol, PBOffLine, PBEject,
    PBOpen, PBHOpen, PBOpenRF, 
    PBHOpenRF, PBLockRange,
    PBUnlockRange, PBRead, PBWrite,
    PBGetFPos, PBSetFPos, PBGetEOF,
    PBSetEOF, PBAllocate, PBAllocContig,
    PBFlushFile, PBClose, PBCreate,
    PBHCreate, PBDirCreate, PBDelete,
    PBHDelete, PBGetFInfo, PBHGetFInfo,
    PBSetFInfo, PBHSetFInfo, PBSetFLock,
    PBHSetFLock, PBRstFLock, PBHRstFLock,
    PBSetFVers, PBRename, PBHRename,
    PBGetCatInfo, PBSetCatInfo, PBCatMove,
    PBOpenWD, PBCloseWD, PBGetWDInfo,
    PBGetFCBInfo;

  TYPE
    ParamBlkType = (ioParam, fileParam,
                    volumeParam, cntrlParam);

    ParmBlkPtr = POINTER TO ParamBlockRec;
    ParamBlockRec = RECORD
      qLink:		QElemPtr;
      qType:		INTEGER;
      ioTrap:		INTEGER;
      ioCmdAddr:	Ptr;
      ioCompletion:	ADDRESS;
      ioResult:		OsErr;
      ioNamePtr:	StringPtr;
      ioVRefNum:	INTEGER;
      CASE ParamBlkType OF
	ioParam:
	  ioRefNum:	INTEGER;
	  ioVersPerm:	ARRAY [0..1] OF CHAR;
	    (* ioVersPerm[0] = ioVersNum
	       ioVersPerm[1] = ioPermssn *)
	  ioMisc:	Ptr;
	  ioBuffer:	Ptr;
	  ioReqCount:	LongCard;
	  ioActCount:	LongCard;
	  ioPosMode:	INTEGER;
	  ioPosOffset:	LongCard;
      | fileParam:
	  ioFRefNum:	INTEGER;
	  ioFVersNum:	ARRAY [0..1] OF CHAR;
	    (* ioFVersNum[0] = ioFVersNum
	       ioFVersNum[1] = filler1 *)
	  ioFDirIndex:	INTEGER;
	  ioFlAttrVers:	ARRAY [0..1] OF CHAR;
	    (* ioFlAttrVers[0] = ioFlAttrib
	       ioFlAttrVers[1] = ioFlVersNum *)
	  ioFlFndrInfo:	FInfo;
	  ioFlNum:	LongCard;
	  ioFlStBlk:	INTEGER;
	  ioFlLgLen:	LongCard;
	  ioFlPyLen:	LongCard;
	  ioFlRStBlk:	INTEGER;
	  ioFlRLgLen:	LongCard;
	  ioFlRPyLen:	LongCard;
	  ioFlCrDat:	LongCard;
	  ioFlMdDat:	LongCard;
      | volumeParam:
	  filler2:	LongCard;
	  ioVolIndex:	INTEGER;
	  ioVCrDate:	LongCard;
	  ioVLsBkUp:	LongCard;
	  ioVAtrb:	INTEGER;
	  ioVNmFls:	INTEGER;
	  ioVDirSt:	INTEGER;
	  ioVBlLn:	INTEGER;
	  ioVNmAlBlks:	INTEGER;
	  ioVAlBlkSiz:	LongCard;
	  ioVClpSiz:	LongCard;
	  ioAlBlSt:	INTEGER;
	  ioVNxtFNum:	LongCard;
	  ioVFrBlk:	INTEGER;
      | cntrlParam:
	  (* used by Device Manager *)
      END;
    END;
    
    CMovePBPtr = POINTER TO CMovePBRec;
    CMovePBRec = RECORD
      qLink:		QElemPtr;
      qType:		INTEGER;
      ioTrap:		INTEGER;
      ioCmdAddr:	Ptr;
      ioCompletion:	ADDRESS;
      ioResult:	OsErr;
      ioNamePtr:	StringPtr;
      ioVRefNum:	INTEGER;
      filler1:		LongCard;
      ioNewName:	StringPtr;
      filler2:		LongCard;
      ioNewDirID:	LongCard;
      filler3:		ARRAY [1..2] OF LongCard;
      ioDirID:		LongCard;
    END;
     
    HParmBlkPtr = POINTER TO HParamBlockRec;
    HParamBlockRec = RECORD
      qLink:		QElemPtr;
      qType:		INTEGER;
      ioTrap:		INTEGER;
      ioCmdAddr:	Ptr;
      ioCompletion:	ADDRESS;
      ioResult:	OsErr;
      ioNamePtr:	StringPtr;
      ioVRefNum:	INTEGER;
      CASE ParamBlkType OF
	ioParam:
	  ioRefNum:	INTEGER;
	  ioVersPerm:	ARRAY [0..1] OF CHAR;
	    (* ioVersPerm[0] = ioVersNum
	       ioVersPerm[1] = ioPermssn *)
	  ioMisc:	Ptr;
	  ioBuffer:	Ptr;
	  ioReqCount:	LongCard;
	  ioActCount:	LongCard;
	  ioPosMode:	INTEGER;
	  ioPosOffset:	LongCard;
      | fileParam:
	  ioFRefNum:	INTEGER;
	  ioFVersNum:	ARRAY [0..1] OF CHAR;
	    (* ioFVersNum[0] = ioFVersNum
	       ioFVersNum[1] = filler1 *)
	  ioFDirIndex:	INTEGER;
	  ioFlAttrVers:ARRAY [0..1] OF CHAR;
	    (* ioFlAttrVers[0] = ioFlAttrib
	       ioFlAttrVers[1] = ioFlVersNum *)
	  ioFlFndrInfo:FInfo;
	  ioDirID:	LongCard;
	  ioFlStBlk:	INTEGER;
	  ioFlLgLen:	LongCard;
	  ioFlPyLen:	LongCard;
	  ioFlRStBlk:	INTEGER;
	  ioFlRLgLen:	LongCard;
	  ioFlRPyLen:	LongCard;
	  ioFlCrDat:	LongCard;
	  ioFlMdDat:	LongCard;
      | volumeParam:
	  filler2:	LongCard;
	  ioVolIndex:	INTEGER;
	  ioVCrDate:	LongCard;
	  ioVLsMod:	LongCard;
	  ioVAtrb:	INTEGER;
	  ioVNmFls:	INTEGER;
	  ioVBitMap:	INTEGER;
	  ioAllocPtr:	INTEGER;
	  ioVNmAlBlks:	INTEGER;
	  ioVAlBlkSiz:	LongCard;
	  ioVClpSiz:	LongCard;
	  ioAlBlSt:	INTEGER;
	  ioVNxtCNID:	LongCard;
	  ioVFrBlk:	INTEGER;
	  ioVSigWord:	INTEGER;
	  ioVDrvInfo:	INTEGER;
	  ioVDRefNum:	INTEGER;
	  ioVFSID:	INTEGER;
	  ioVBkUp:	LongCard;
	  ioVSeqNum:	INTEGER;
	  ioVWrCnt:	LongCard;
	  ioVFilCnt:	LongCard;
	  ioVDirCnt:	LongCard;
	  ioVFndrInfo:	ARRAY [1..8] OF LongCard;
      END;
    END;

    WDPBPtr = POINTER TO WDPBRec;
    WDPBRec = RECORD
      qLink:		QElemPtr;
      qType:		INTEGER;
      ioTrap:		INTEGER;
      ioCmdAddr:	Ptr;
      ioCompletion:	ADDRESS;
      ioResult:	OsErr;
      ioNamePtr:	StringPtr;
      ioVRefNum:	INTEGER;
      filler1:		INTEGER;
      ioWDIndex:	INTEGER;
      ioWDProcID:	LongCard;
      ioWDVRefNum:	INTEGER;
      filler2:		ARRAY [1..7] OF INTEGER;
      ioWDDirID:	LongCard;
    END;
     
    CInfoType = (hFileInfo, dirInfo);
    CInfoPBPtr = POINTER TO CInfoPBRec;
    CInfoPBRec = RECORD
      qLink:		QElemPtr;
      qType:		INTEGER;
      ioTrap:		INTEGER;
      ioCmdAddr:	Ptr;
      ioCompletion:	ADDRESS;
      ioResult:	OsErr;
      ioNamePtr:	StringPtr;
      ioVRefNum:	INTEGER;
      ioFRefNum:	INTEGER;
      filler1:		INTEGER;
      ioFDirIndex:	INTEGER;
      ioFlAttrib:	ARRAY [0..1] OF CHAR;
	(* ioFlAttrib[0] = ioFlAttrib
	   ioFlAttrib[1] = filler2 *)
      CASE CInfoType OF
	hFileInfo:
	  ioFlFndrInfo:FInfo;
	  ioFlNum:	LongCard;
	  ioFlStBlk:	INTEGER;
	  ioFlLgLen:	LongCard;
	  ioFlPyLen:	LongCard;
	  ioFlRStBlk:	INTEGER;
	  ioFlRLgLen:	LongCard;
	  ioFlRPyLen:	LongCard;
	  ioFlCrDat:	LongCard;
	  ioFlMdDat:	LongCard;
	  ioFlBkDat:	LongCard;
	  ioFlXFndrInfo:FInfo;
	  ioFlParID:	LongCard;
	  ioFlClpSiz:	LongCard;
      | dirInfo:
	  ioDrUsrWds:	ARRAY [1..8] OF INTEGER;
	  ioDrDirID:	LongCard;
	  ioDrNmFls:	INTEGER;
	  filler3:	ARRAY [1..9] OF INTEGER;
	  ioDrCrDat:	LongCard;
	  ioDrMdDat:	LongCard;
	  ioDrBkDat:	LongCard;
	  ioDrFndrInfo:ARRAY [1..8] OF INTEGER;
	  ioDrParID:	LongCard;
       END;
    END;

    FCBPBPtr = POINTER TO FCBPBRec;
    FCBPBRec = RECORD
      qLink:		QElemPtr;
      qType:		INTEGER;
      ioTrap:		INTEGER;
      ioCmdAddr:	Ptr;
      ioCompletion:	ADDRESS;
      ioResult:		OsErr;
      ioNamePtr:	StringPtr;
      ioVRefNum:	INTEGER;
      ioRefNum:		INTEGER;
      filler1:		INTEGER;
      ioFCBIndx:	LongCard;
      ioFCBFlNm:	LongCard;
      ioFCBFlags:	INTEGER;
      ioFCBStBlk:	INTEGER;
      ioFCBEOF:		LongCard;
      ioFCBPLen:	LongCard;
      ioFCBCrPs:	LongCard;
      ioFCBVRefNum:	INTEGER;
      ioFCBClpSiz:	LongCard;
      ioFCBParID:	LongCard;
    END;

    PROCEDURE PBMountVol
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBGetVInfo
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBHGetVInfo
    	(pBlk: HParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBHSetVInfo
    	(pBlk: HParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBGetVol
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBHGetVol
    	(pBlk: HParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBSetVol
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBHSetVol
    	(pBlk: WDPBPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBFlushVol
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBUnmountVol
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBOffLine
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBEject
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBOpen
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBHOpen
    	(pBlk: HParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBOpenRF
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBHOpenRF
    	(pBlk: HParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBLockRange
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBUnlockRange
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBRead
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBWrite
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBGetFPos
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBSetFPos
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBGetEOF
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBSetEOF
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBAllocate
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBAllocContig
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBFlushFile
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBClose
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBCreate
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBHCreate
    	(pBlk: HParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBDirCreate
    	(pBlk: HParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBDelete
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBHDelete
    	(pBlk: HParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBGetFInfo
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBHGetFInfo
    	(pBlk: HParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBSetFInfo
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBHSetFInfo
    	(pBlk: HParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBSetFLock
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBHSetFLock
    	(pBlk: HParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBRstFLock
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBHRstFLock
    	(pBlk: HParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBSetFVers
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBRename
    	(pBlk: ParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBHRename
    	(pBlk: HParmBlkPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBGetCatInfo
    	(pBlk: CInfoPBPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBSetCatInfo
    	(pBlk: CInfoPBPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBCatMove
    	(pBlk: CInfoPBPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBOpenWD
    	(pBlk: WDPBPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBCloseWD
    	(pBlk: WDPBPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBGetWDInfo
    	(pBlk: WDPBPtr; async: BOOLEAN) : OsErr;
    PROCEDURE PBGetFCBInfo
    	(pBlk: FCBPBPtr; async: BOOLEAN) : OsErr;

END PBFileManager.
